package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.SettlementInfo;
import java.util.ArrayList;
import java.util.List;

public class SettlementInfoAdapter<T> extends BaseAdapter {

  private List<T> objects = new ArrayList<T>();

  private Context context;
  private LayoutInflater layoutInflater;

  public SettlementInfoAdapter(Context context, ArrayList<T> obj) {
    this.context = context;
    this.objects = obj;
    this.layoutInflater = LayoutInflater.from(context);
  }

  @Override public int getCount() {
    return objects.size();
  }

  @Override public T getItem(int position) {
    return objects.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView = layoutInflater.inflate(R.layout.adapter_settlement_info, null);
      convertView.setTag(new ViewHolder(convertView));
    }
    initializeViews((T) getItem(position), (ViewHolder) convertView.getTag());
    return convertView;
  }

  private void initializeViews(T object, ViewHolder holder) {
    SettlementInfo item = (SettlementInfo) object;
    holder.tvNameSettlementInfo.setText(item.getName());
    holder.tvCostSettlementInfoItem.setText(String.valueOf(item.getCost()) + "元");
    holder.tvDateSettlementInfo.setText(item.getDate());
  }

  static class ViewHolder {
    @BindView(R.id.tv_name_settlementInfo) TextView tvNameSettlementInfo;
    @BindView(R.id.tv_date_settlementInfo) TextView tvDateSettlementInfo;
    @BindView(R.id.tv_cost_settlementInfoItem) TextView tvCostSettlementInfoItem;

    ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }

  @Override public boolean isEmpty() {
    return false;
  }
}
